package com.bjmashibing.system.OSFileIO.io_demo.demo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyPicture {
    public static void main(String[] args) throws IOException {
        copyPic();
    }

    private static void copyPic() throws IOException {
        FileInputStream inputStream=new FileInputStream("src/Java_IO/io_demo/Resources/1.jpg");
        FileOutputStream outputStream = new FileOutputStream("src/Java_IO/io_demo/Resources/2.jpg");

        int length=0;
        byte[] buffer=new byte[1024];
        while ((length=inputStream.read(buffer))!=-1){//每次while循环都是读1024个字节到buffer数组中，直到遇到文件末尾
            outputStream.write(buffer);
        }
        outputStream.close();
        inputStream.close();
    }
}
